using Microsoft.Extensions.DependencyInjection;
using NLog.Web;
using StackExchange.Redis;
using Xunit.Abstractions;

namespace Crux.Core.Cache.Extensions.Test;
/// <summary>
/// TestHybridCache
/// </summary>
public class TestHybridCache
{
    protected readonly ITestOutputHelper output;
    protected IServiceProvider? serviceProvider;
    public TestHybridCache(ITestOutputHelper output)
    {
        this.output = output;
        this.InitServiceProvider();
    }
    private void InitServiceProvider()
    {
        IServiceCollection services = new ServiceCollection();
        services.AddMemoryCache();
        services.AddLogging((builder) =>
        {
            builder.AddNLogWeb();
        });
        services.Configure<HybridCacheOption>(option =>
        {
            option.AbsoluteExpiration = TimeSpan.FromHours(1);
            option.RandomSlidingSecond = 60;
            option.SlidingExpiration = TimeSpan.FromSeconds(10);
        });
        services.Configure<ConfigurationOptions>(option =>
        {
            option.KeepAlive = 1800;
            option.ConnectTimeout = 15000;
            option.AbortOnConnectFail = true;
            option.AllowAdmin = false;
            option.ChannelPrefix = RedisChannel.Pattern("EntranceDesire");
            option.ConnectRetry = 3;
            option.ClientName = "EntranceDesire";
            // option.Password = "123456";
            option.Proxy = Proxy.None;
            option.ResolveDns = false;
            option.Ssl = false;
            option.SslHost = null;
            option.SyncTimeout = 10000;
            option.ServiceName = null;
            option.DefaultDatabase = 14;

            option.EndPoints.Add("redis_master", 6379);
        });
        services.AddRedisSupport();
        services.AddHybridCache();

        this.serviceProvider = services.BuildServiceProvider();
    }
}